<?php
namespace app\agent\servlet;

class WkSellerexServlet extends BaseServlet
{
	public function __construct()
	{
		parent::__construct();
	}

	/**
	* 组装查询条件
	* @param array $data
	* @return array
	*/
    public function getWhere($data = [])
    {
        $where = [];

        if( empty($data) )
        {
            return $where;
        }

        if( empty($data['id']) === false )
        {
            $where[] = ['sellerex.id', '=', $data['id']];
        }

        if( empty($data['uid']) === false )
        {
            $where[] = ['sellerex.uid', '=', $data['uid']];
        }

        if( empty($data['shopname']) === false )
        {
            $where[] = ['shopname', 'LIKE', "%{$data['shopname']}%"];
        }

        if( empty($data['province']) === false )
        {
            $where[] = ['sellerex.province', '=', $data['province']];
        }

        if( empty($data['city']) === false )
        {
            $where[] = ['sellerex.city', '=', $data['city']];
        }

        if( empty($data['county']) === false )
        {
            $where[] = ['sellerex.county', '=', $data['county']];
        }

        if( empty($data['user_id']) === false )
        {
            $where[] = ['user_id', '=', $data['user_id']];
        }

        if( empty($data['tel']) === false )
        {
            $where[] = ['tel', 'LIKE', "%{$data['tel']}%"];
        }

        if ( empty($data['stime']) === false && empty($data['etime']) === false )
        {
            $where[] = ['checkTime', 'BETWEEN TIME', [$data['stime'], $data['etime']]];
        }

        return $where;
    }

	/**
	* 整理数据
	* @param array $data
	* @return array
	*/
	public function collating($data = [])
	{
		if( empty($data) )
		{
			return $data;
		}

        if( empty($data['type']) === false && empty($data['addr_code'] === false) )
        {
            $type = [
                1 => 'province',
                2 => 'city',
                3 => 'county',
            ];

            $data[$type[$data['type']]] = $data['addr_code'];
        }

		return $data;
	}
}